package guiPackage;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import systemPackage.LocalStrings;
import systemPackage.MainSystem;

import dataTypesPackage.Musteri;

public class GUI_editMusteri extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = -7032807731565447556L;
	
	@SuppressWarnings("unused")
	private JLabel musteriIDLabel;
	private JLabel nameLabel;
	private JLabel surNameLabel;
	
	@SuppressWarnings("unused")
	private JLabel newNameLabel = new JLabel(LocalStrings.getLocalString(1));
	private JTextField newNameField = new JTextField();
	@SuppressWarnings("unused")
	private JLabel newSurNameLabel = new JLabel(LocalStrings.getLocalString(2));
	private JTextField newSurNameField = new JTextField();
		
	private JButton saveButton = new JButton(LocalStrings.getLocalString(3));
	
	
	public GUI_editMusteri(){
		int musteriID = Integer.valueOf(JOptionPane.showInputDialog(LocalStrings.getLocalString(6)));
		Musteri musteri = (Musteri) MainSystem.get(musteriID, Musteri.class);
		createWindow(musteri);
	}
	
	public void createWindow(final Musteri musteri){
		this.setDefaultCloseOperation ( JFrame.DISPOSE_ON_CLOSE );
		musteriIDLabel = new JLabel(String.valueOf(musteri.getMusteriID()));
		nameLabel = new JLabel(musteri.getName());
		surNameLabel = new JLabel(musteri.getSurName());
		
		Container container = getContentPane();
		container.setLayout(new GridLayout(5,2));
		container.add(nameLabel);
		container.add(surNameLabel);
		container.add(newNameField);
		container.add(newSurNameField);
		ActionListener saveButtonPress = new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// This method calls for mainSystem to edit client 
				musteri.setName(newNameField.getText());
				musteri.setSurName(newSurNameField.getText());
				MainSystem.editMusteri(musteri);
				dispose();
			}
		};
		saveButton.addActionListener(saveButtonPress);
		container.add(saveButton);
		this.setSize(240, 200);

	}
	


	
}
